package com.mission.shaco.warehouse.models.list

import org.json.JSONArray
import org.json.JSONObject
import java.util.ArrayList

/**
 * Created by Administrator on 2017/6/20.
 */
public class MultiList : BaseList() {
    private val serialVersionUID = 7981560250804001000L

//    fun takeWrongItem(error:String,position:Int) {
//        var js = jsonArray.get(position) as JSONObject
//
//        val len = jsonArray.length()
//        val result = ArrayList<JSONObject>(len)
//        var rmList = ArrayList<Int>()
//        for (i in 0..len - 1) {
//            val obj = jsonArray.optJSONObject(i)
//            if (obj.getString("grid") == js.getString("grid") ) {
//                rmList.add(i)
//                if(i == position){
//                    obj.put("errorCode",  error)
//                }else {
//                    obj.put("errorCode", "订单其他条目异常 :" + obj.getString("id") + error)
//                }
//                this.wrongItemArray.put(obj)
//            }
//        }
//
//        rmList.sortDescending()
//        for (i in 0..rmList.size -1){
//            removePosition(rmList[i])
//        }
//
//    }

    fun takeWrongItem(error:String,position:Int) {
        var js = jsonArray.get(position) as JSONObject

        var qty = js.getInt("qty")

        var overQty = 0;
        if(js.has("qty_bak")){
            overQty = js.getInt("qty_bak")
            js.put("qty",qty-overQty)
            this.completeArray.put(js)
            val wrongjs = JSONObject(js.toString())

            wrongjs.put("errorCode",error)
            wrongjs.put("qty",overQty)
            this.wrongItemArray.put(wrongjs)
        }else{
            js.put("errorCode",error)
            this.wrongItemArray.put(js)
        }

        removePosition(position)
    }



    fun overdueCheck():Boolean{

        if(upload==1 ){
            return true
        }

        if(completeArray.length() ==0 && jsonArray.length() ==0){
            return true
        }

        var nowTime = System.currentTimeMillis()/1000
        if( nowTime - lifeTime > 24 * 60 * 60){
            return true;
        }else{
            return false;
        }

    }

}